﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Sector7.Restaurant.APs.ForeStation.Entity;
using Sector7.Restaurant.APs.ForeStation.Enums;
using Sector7.Restaurant.APs.ForeStation.Events;

namespace Sector7.Restaurant.APs.ForeStation.Controls
{
    /// <summary>
    /// MenuStrip.xaml 的交互逻辑
    /// </summary>
    public partial class MenuStrip : UserControl
    {
        public event MenuClickEventHandler MenuClick = null;

        public MenuStrip()
        {
            InitializeComponent();            
        }

        public void LoadFunctionItems(List<FunctionItemInfor> functionItems)
        {
            tlbMain.Items.Clear();
            foreach (var functionItem in functionItems)
            {
                CheckBox ckb = new CheckBox();
                ckb.Content = functionItem.Caption;
                ckb.Tag = functionItem.ItemType;
                ckb.Width = 80;
                ckb.Height = 30;
                ckb.Padding = new Thickness(7, 0, 7, 0);
                ckb.Checked += new RoutedEventHandler(CheckBox_Checked);

                tlbMain.Items.Add(ckb);
            }

            CheckBox ckbFirst = tlbMain.Items[0] as CheckBox;
            ckbFirst.IsChecked = true;
            OnMenuClick(new MenuClickEventArgs((MenuItemType)ckbFirst.Tag));
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            foreach (CheckBox ckb in tlbMain.Items)
            {
                if (ckb != sender)
                {
                    ckb.IsChecked = false;
                }
            }

            OnMenuClick(new MenuClickEventArgs((MenuItemType)(sender as CheckBox).Tag));
        }

        protected void OnMenuClick(MenuClickEventArgs e)
        {
            if (null != MenuClick)
                MenuClick(this, e);
        }

        private void tlbMain_Loaded(object sender, RoutedEventArgs e)
        {
            ToolBar toolBar = sender as ToolBar;

            var overflowGrid = toolBar.Template.FindName("OverflowGrid", toolBar) as FrameworkElement;

            if (null != overflowGrid)
            {
                overflowGrid.Visibility = Visibility.Hidden;
            }

            var toolBarThumb = toolBar.Template.FindName("ToolBarThumb", toolBar) as FrameworkElement;

            if (null != toolBarThumb)
            {
                toolBarThumb.Visibility = Visibility.Hidden;
            }
        }
    }
}
